package ecoiot.com.testproject.menu;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import ecoiot.com.testproject.R;

@SuppressLint("NewApi")
public class TestSlideMenuActivity extends AppCompatActivity {


    private TestSlideMenu slideMenu;
    private Button btnShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_slide_menu);

        slideMenu = (TestSlideMenu) findViewById(R.id.activity_slide_menu_tsm);

        slideMenu.setMenuAdapter(new MyAdapter());

        btnShow = (Button) findViewById(R.id.btn_show_menu);

        btnShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean isMenuShow = slideMenu.changeMenuState();
                if (isMenuShow) {
                    btnShow.setText("关闭菜单");
                }else {
                    btnShow.setText("打开菜单");
                }
            }
        });

        slideMenu.setOnMenuStateChangedListener(new TestSlideMenu.OnMenuStateChangedListener() {
            @Override
            public void onStateChanged(boolean isMenuShow) {
                if (isMenuShow) {
                    btnShow.setText("关闭菜单");
                }else {
                    btnShow.setText("打开菜单");
                }
            }
        });

    }


    private class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 20;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView textView = new TextView(TestSlideMenuActivity.this);

            textView.setText("1234567890");
            textView.setTextSize(25);

//            viewGroup.addView(textView);

            return textView;
        }
    }
}
